const express = require('express');
const router = express.Router();
const pool = require('../pool.js');

router.get('/getInfo',function(req,res,next){
	const openid = req.query.openid;
	pool.getConnection(function(error, connection){
		if(error){
			throw error;
		}
		const getSql = 'SELECT * FROM userOrder WHERE openid = ?';
		connection.query(getSql, [openid], function(err, results, fields){
			if(err){
				throw err;
			}
			connection.release();
			let obj = results[0];
            // 如果用户的昵称超过5个字符，则从前往后截取5个字符，超出的部分舍弃
			if (obj.marking.length > 5) {
				obj.marking = obj.marking.substr(0,5);
			}
			res.json(obj);
		});
	});
});

module.exports = router;